#include "util.h"
#include <stdlib.h>     /* srand, rand */
#include <time.h>
#include <algorithm>

namespace util {

void swap(std::vector<int>& vec, int i, int j) {
	if (vec[i] == vec[j]) {
		return;
	}

	vec[i] = vec[i] ^ vec[j];
	vec[j] = vec[i] ^ vec[j];
	vec[i] = vec[i] ^ vec[j];
}

void print(const std::vector<int>& vec) {
	int len = vec.size();

	std::cout << "this vec is: [";
	for (int i = 0; i < len; ++i) {
		std::cout << vec[i];
		if (i != len - 1) {
			std::cout << ", ";
		}
	}
	std::cout << "]" << std::endl;
}

void comparator(std::vector<int>& vec) {
	std::sort(vec.begin(), vec.end());
}

std::vector<int> generateRandomArray(int maxSize, int maxValue) {
	const int len = (int)(rand() % maxValue + 1);

	std::vector<int> vec;
	vec.resize(len);

	for (int i = 0; i < len; ++i) {
		vec[i] = (int) ((rand() % maxValue + 1) - (rand() % maxValue));
	}

	return vec;
}

std::vector<int> copyArray(const std::vector<int>& vec) {
	int len = vec.size();

	std::vector<int> res;
	res.resize(len);

	if (len) {
		for (int i = 0; i < len; ++i) {
			res[i] = vec[i];
		}
	}

	return res;
}

bool isEqual(const std::vector<int>& vec1, const std::vector<int>& vec2) {
	int sz1 = vec1.size();
	int sz2 = vec2.size();
	if (sz1 != sz2) {
		return false;
	}

	for (int i = 0; i < sz1; ++i) {
		if (vec1[i] != vec2[i]) {
			return false;
		}
	}

	return true;
}

}


